package com.demo.aop.before.simple;

import com.demo.aop.sing.Singer;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;

import java.lang.reflect.Method;

/**
 * 描述：
 *
 * @author lida
 * @time 2019/10/22 18:00
 */
public class SimpleBeforeMain implements MethodBeforeAdvice {

	public static void main(String[] args) {
		Guitarist guitarist = new Guitarist();

		//创建代理工厂
		ProxyFactory pf = new ProxyFactory();
		pf.addAdvice(new SimpleBeforeMain());
		pf.setTarget(guitarist);

		//获得代理后的对象
		Singer singer = (Guitarist)pf.getProxy();
		singer.sing();
	}

	@Override
	public void before(Method method, Object[] args, Object target) throws Throwable {
		System.out.println("Before Method: method's name---" + method.getName());
	}
}
